/* eslint-disable */
import Vue from 'vue'
import VueRouter from 'vue-router'

// import Login from '@/components/myLogin.vue'
const Login = () => import (/* webpackChunkName: "login_home_welcome" */ '@/components/myLogin.vue')
// import Home from '@/components/myHome.vue'
const Home = () => import (/* webpackChunkName: "login_home_welcome" */ '@/components/myHome.vue')
// import Welcome from '@/components/welcomeTo.vue'
const Welcome = () => import (/* webpackChunkName: "login_home_welcome" */ '@/components/welcomeTo.vue')


// import UserInfo from '@/components/User/userInfo.vue'
const UserInfo = () => import (/* webpackChunkName: "UserInfo_Rights_Roles" */ '@/components/User/userInfo.vue')
// import Rights from '@/components/Power/tRights.vue'
const Rights = () => import (/* webpackChunkName: "UserInfo_Rights_Roles" */ '@/components/Power/tRights.vue')
// import Roles from '@/components/Power//tRoles.vue'
const Roles = () => import (/* webpackChunkName: "UserInfo_Rights_Roles" */ '@/components/Power/tRoles.vue')

// import Cate from '@/components/goods/gCate.vue'
const Cate = () => import (/* webpackChunkName: "Cate_Params" */ '@/components/goods/gCate.vue')
// import Params from '@/components/goods/gParams.vue'
const Params = () => import (/* webpackChunkName: "Cate_Params" */ '@/components/goods/gParams.vue')

// import List from '@/components/goods/tList.vue'
const List = () => import (/* webpackChunkName: "List_Add" */ '@/components/goods/tList.vue')
// import Add from '@/components/goods/gAdd.vue'
const Add = () => import (/* webpackChunkName: "List_Add" */ '@/components/goods/gAdd.vue')

// import Order from '@/components/order/tOrder.vue'
const Order = () => import (/* webpackChunkName: "Order_Report" */ '@/components/order/tOrder.vue')
// import Report from '@/components/Report/tReport.vue'
const Report = () => import (/* webpackChunkName: "Order_Report" */ '@/components/Report/tReport.vue')

Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    { path: '/', redirect: '/login' },
    { path: '/login', component: Login },
    {
      path: '/home',
      component: Home,
      redirect: '/welcome',
      children: [
        { path: '/welcome', component: Welcome },
        { path: '/users', component: UserInfo },
        { path: '/rights', component: Rights },
        { path: '/roles', component: Roles },
        { path: '/categories', component: Cate },
        { path: '/params', component: Params },
        { path: '/goods', component: List },
        { path: '/goods/add', component: Add },
        { path: '/orders', component: Order },
        { path: '/reports', component: Report }
      ]
    }
  ]
})

// 全局前置守卫
router.beforeEach(function(to, from, next) {
  if(to.path === '/login') return next()
  const token = window.sessionStorage.getItem('token')
  if(!token) return next('/login')
  next()
})
export default router
